﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="java.util.*,com.javabean.*"
	import="java.sql.*"%>
<%@page import="com.javabean.IsDeadline"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../js/jquery-1.9.1.min.js" type="text/javascript"></script>
<style type="text/css">
a.import:link {text-decoration:none;}
a.import:visited {text-decoration:none;}
a.import:hover {text-decoration:none;}
a.import:active {text-decoration:none;}
</style>
<script type="text/javascript">
	function checkMaxTime(time1) {
		var d1 = new Date();
		var d2 = new Date(time1.replace(/-/g, "/"));
		if (Date.parse(d1) - Date.parse(d2) > 0)
			return true;//过期
		else
			return false;
	}
	function getCom(page, tem) {
		var req = 0;
		if (tem == 0) {
			req = "listdev";
		}
		if (tem == 1) {
			req = "select";
		}
		$
				.post(
						req,
						{
							requestPage : page,
							type : $("#sss").val(),
							shuru : $("#iii").val(),
							isUse : "yes"
						},
						function(data) {

							var json = data.dev;
							$(".resultList").remove();
							for ( var i = 0; i < (json.length - 1); i++) {
								//alert(json.length+i);
								$("#infos")
										.append(
												"<tr id='resultList"+ json[i].did +"' class='resultList' align='center'>"
														+ "<td bgcolor='#FFFFFF'><input type='checkbox' name='delid' value='"+json[i].did+"'/></td>"
														+ "<td height='20' bgcolor='#FFFFFF'>"
														+ json[i].name
														+ "</td>"
														+ "<td bgcolor='#FFFFFF'>"
														+ json[i].devid
														+ "</td>"
														+ "<td bgcolor='#FFFFFF'>"
														+ json[i].devmodel
														+ "</td>"
														+ "<td bgcolor='#FFFFFF'>"
														+ json[i].depart
														+ "</td>"
														+ "<td bgcolor='#FFFFFF'><a href='SB_BJ.jsp?devids="
														+ json[i].did
														+ "'>编辑</a>"
														+ " | <a href='SB_CK1.jsp?devids="
														+ json[i].did
														+ "'>查看</a>"
														+ " | <a href='SB_ZY.jsp?devids="
														+ json[i].did
														+ "'>转移</a></td></tr>");
								var time = json[i].endDate;
								//alert(time);
								if (checkMaxTime(time)) {
									$("#resultList" + json[i].did).addClass(
											"resultListR");
								} else {
									$("#resultList" + json[i].did).removeClass(
											"resultListR");
								}
							}

							$("#totalset")
									.html(json[json.length - 1].totalPage);
							$("#curpage").html(json[json.length - 1].curPage);
							if (json[json.length - 1].curPage < json[json.length - 1].totalPage) {
								$("#nextpage").attr("dir",
										json[json.length - 1].curPage);
							}
							if (json[json.length - 1].curPage > 1) {
								$("#prepage").attr("dir",
										json[json.length - 1].curPage);
							}
						}, "json");
	}
	$(document).ready(function() {
		getCom(1, 0);
		/*Get next page */
		$("#nextpage").bind("click", function() {
			if ($("#nextpage").attr("dir") != "0") {
				var page = parseInt($("#nextpage").attr("dir")) + 1;
				getCom(page, 0);
			}
		});
		/*Get preceding page */
		$("#prepage").bind("click", function() {
			if ($("#nextpage").attr("dir") != "0") {
				var page = parseInt($("#prepage").attr("dir")) - 1;
				getCom(page, 0);
			}
		});

		$("#tiao").click(function() {
			if ($("p").val() > 1 && $("p").val() < $("#totalset").html()) {
				getCom(1, 0);
			}
		});
	});
</script>
<title></title>
<style type="text/css">
<!--
body {
	background-color: #fff;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.tabfont01 {
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}

.font051 {
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}

.font201 {
	font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}

html {
	overflow-x: auto;
	overflow-y: auto;
	border: 0;
}

.resultListR {
	color: red;
}

。resultList {
	
}
-->
</style>
<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
	$(function() {
		document.onkeydown = function(event) {
			var e = document.all ? window.event : event;

			if (e && e.keyCode == 13) { // enter 键
				return false;
				//要做的事情
			}
		}
	})
	function sbbj() {
		opener.document.getElementById("mainFrame");
	}

	function selectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				obj[i].checked = true;
			}
		}
	}

	function unselectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true)
					obj[i].checked = false;
				else
					obj[i].checked = true;
			}
		}
	}

	function link() {
		document.getElementById("fom").removeAttribute("enctype");
		document.getElementById("fom").method = "get";
		document.getElementById("fom").action = "SB_TJ.jsp";
		document.getElementById("fom").submit();
	}
	function link2() {
		document.getElementById("fom").removeAttribute("enctype");
		document.getElementById("fom").method = "get";
		document.getElementById("fom").action = "SB_BF.jsp";
		document.getElementById("fom").submit();
	}
	function deletedev() {
		var obj = document.fom.elements;
		var x = 0;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true) {
					x++;
				}
			}
		}
		if (x > 0) {
			if (confirm("确认删除所选设备？")) {
				document.fom.action = "DeviceDeal?flag=delete";
				document.fom.submit();
			}
		} else {
			window.alert("请选择需要删除的设备");
			return;
		}
	}
	function bfdev() {
		var obj = document.fom.elements;
		var x = 0;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true) {
					x++;
				}
			}
		}
		if (x > 0) {
			if (confirm("确认该设备已报废？")) {
				fom.action = "DeviceDeal?flag=scrap";
				document.fom.submit();
			}
		} else {
			window.alert("请选择需要报废的设备");
			return;
		}
	}
	function deviceImport() {
		document.getElementById("fom").enctype = "multipart/form-data";
		document.getElementById("fom").method = "post";
		document.getElementById("fom").action = "DeviceDeal?flag=import";
		document.getElementById("fom").submit();
	}
	function deviceExport() {
		document.getElementById("fom").removeAttribute("enctype");
		document.getElementById("fom").method = "post";
		document.getElementById("fom").action = "DeviceDeal?flag=export";
		document.getElementById("fom").submit();
	}
</script>
</head>

<body>
	<form name="fom" id="fom" method="post">
		<%
			IsDeadline find = new IsDeadline();
			ArrayList overTime = find.findOverTime();
			String dev = " ";
			for (int i = 0; i < overTime.size(); i++) {
				dev += overTime.get(i).toString();
				dev += "	";
			}

			if (dev != " ") {
				out.print("<script>alert(' 设备名称为【" + overTime.get(0).toString()
						+ "】,设备编号为【" + overTime.get(1).toString()
						+ "】上述设备已经超期');</script>");

			}
		%>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

			<tr>
				<td height="30">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td height="62" background="../image/widgetbg5.jpg">

								<table width="98%" border="0" align="center" cellpadding="0"
									cellspacing="0">
									<tr>
										<td width="24"><img src="../images/ico07.gif" width="20"
											height="18" /></td>
										<td width="519"><select name="select2" id="sss">
												<option>设备名称</option>
												<option>设备编号</option>
										</select> <input name="textfield" type="text" size="12" id="iii" /><span
											class="newfont06" /> <input name="search" type="button"
											value="查 询" onclick="getCom(1,1)" /></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td><table id="subtree1" style="DISPLAY:" width="100%" border="0"
						cellspacing="0" cellpadding="0">
					<tr>
						<td>
							<table width="95%" border="0" align="center"
									cellpadding="5" cellspacing="0">
								<tr>
									<td height="20"><span class="newfont07">选择：<a
										href="#" class="right-font08" onclick="selectAll();">全选</a>-<a
										href="#" class="right-font08" onclick="unselectAll();">反选</a></span>
											<%
												//从session中取出用户的级别
												int userGrade = ((User) request.getSession(true).getAttribute(
														"user")).getUserGrade();
												boolean isAuthority = false;
												if (userGrade != 0 && userGrade != 1 && userGrade != 2
														&& userGrade != 3 && userGrade != 8 && userGrade != 9
														&& userGrade != 10 && userGrade != 11) {
													isAuthority = true;
												}
											%>
											<%
												if (isAuthority) {
											%> <input name="" type="button" value="删除信息"
											onclick="deletedev()" /> <input name="" type="button"
											value="添加信息" onclick="link();" /> <input name=""
											type="button" value="设备报废" onclick="bfdev()" /> <input
											type="file" name="upload" id="upload"
											onchange="deviceImport();" hidden="hidden"
											style="border: solid 1px #eee; width: 200px" />
											<a class="import" title="信息导入支持xls格式的批量资产信息导入功能，&#10格式为‘类型，编号，型号，厂家，制造日期，截止日期，部门，备注’，&#10其中日期格式为 ‘2013-05-01’或‘2013-5-1’&#10备注列可以为空，数据应从第一行至最后一行存放">
											<input
											name="import" type="button"
											onclick="document.getElementById('upload').click();"
											value="信息导入" /></a>
											<a class="import" title="导入格式样例下载" href="../xls/device.xls"><img width="15" height="15" alt="导入格式样例下载" src="../images/help.png"/></a>
											<input name="export" type="button"
											onclick="deviceExport();" value="信息导出" />
											<%}%>
											<input name=""
											type="button" value="报废列表" onclick="link2();" />
											</td>
									</tr>
									<tr>
										<td height="40" class="font42">
											<table id="infos" width="100%" border="0" cellpadding="4"
												cellspacing="1" bgcolor="#464646" class="newfont03">
												<tr>
													<td height="20" colspan="6" align="center"
														class="tablestyle_title">设备信息列表</td>
												</tr>
												<tr>
													<td width="5%" align="center" class="zsd">选择</td>
													<td width="30%" height="20" align="center" class="zsd">设备名称</td>
													<td width="15%" align="center" class="zsd">设备编号</td>
													<td width="15%" align="center" class="zsd">设备型号</td>
													<td width="20%" align="center" class="zsd">使用部门</td>
													<td width="15%" align="center" class="zsd">操作</td>
												</tr>
											</table>
										</td>
									</tr>
								</table></td>
						</tr>
					</table>
					<table width="95%" border="0" align="center" cellpadding="0"
						cellspacing="0">

						<tr>
							<td height="33"><table width="100%" border="0"
									align="center" cellpadding="0" cellspacing="0"
									class="right-font08">
									<tr>
										<td width="50%">共 <span id="totalset"
											class="right-text09">5</span> 页 | 第 <span id="curpage"
											class="right-text09">1</span> 页
										</td>
										<td width="49%" align="right">[<a id="headpage" href="#"
											class="right-font08"></a> | <a id="prepage" dir="0" href="#"
											class="right-font08">上一页</a> | <a id="nextpage" dir="0"
											href="#" class="right-font08">下一页</a> | <a id="finalpage"
											href="#" class="right-font08"></a>]
										</td>
										<td width="1%"><table width="20" border="0"
												cellspacing="0" cellpadding="0">
												<!--  <tr>
													<td width="1%"><input id="p" name="textfield3"
														type="text" class="right-textfield03" size="1" /></td>
													<td width="87%"><input id="tiao" name="Submit23222"
														type="submit" class="right-button06" value=" " /></td>
												</tr>  -->
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table></td>
			</tr>
		</table>
	</form>
</body>
</html>
